package com.example.lib5.sort.Interface;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.Scanner;

public class Test1 {
    public static void main(String[] args) {
//        链接：https://www.nowcoder.com/questionTerminal/dfeed0e0e4624814b122265e859783b2
//        来源：牛客网

        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        scanner.nextLine();
        ArrayList<String> list = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            String line = scanner.nextLine();
            if (line.equals("stop")) break;
            else list.add(line);
        }
        list.sort(Comparator.comparingInt(String::length));
        for (String s : list) System.out.println(s);
    }
}
